package com.zsl.swing.redis.desktop.type;

import java.util.Arrays;

public enum UnitTypeEnum {

    MILLIS("毫秒"),SECONDS("秒"),MINUTES("分钟"),HOURS("小时"),DAYS("天");

    private String unitName;

    UnitTypeEnum(String unitName){
        this.unitName = unitName;
    }

    public String getUnitName(){
        return this.unitName;
    }

    public static Integer toSeconds(String unitName, int num){
        UnitTypeEnum unitTypeEnum = Arrays.stream(values()).filter(u -> u.getUnitName().equals(unitName)).findAny().get();
        switch (unitTypeEnum){
            case MILLIS:
                return num /1000;
            case SECONDS:
                return num;
            case MINUTES:
                return num * 60;
            case HOURS:
                return num * 60 * 60;
            case DAYS:
                return num *24 *60 * 60;
            default: return null;
        }
    }
}
